<?php

/**
 * Nexcess.net Turpentine Extension for Magento
 * Copyright (C) 2012  Nexcess.net L.L.C.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

?>
<br />
<div class="content-header">
    <table cellspacing="0">
        <tr>
            <td>
                <h3><?php echo Mage::helper( 'turpentine/data' )
                        ->__('Varnish Management') ?></h3>
            </td>
            <td class="form-buttons"></td>
         </tr>
    </table>
</div>
<table class="form-list varnish-management">
    <tr>
        <td class="scope-label">
            <button
                onclick="setLocation('<?php echo $this->getApplyConfigUrl()?>')"
                type="button"
                class="scalable save">
                <span><?php echo Mage::helper( 'turpentine/data' )
                        ->__('Apply Varnish Config') ?></span>
            </button>
        </td>
        <td class="scope-label">
            <?php echo Mage::helper( 'turpentine/data' )
                ->__('Update the VCL configuration on the running Varnish instances')?>
        </td>
    </tr>
    <tr>
        <td class="scope-label">
            <button
                onclick="setLocation('<?php echo $this->getSaveConfigUrl()?>')"
                type="button"
                class="scalable save">
                <span><?php echo Mage::helper( 'turpentine/data' )
                        ->__('Save Varnish Config') ?></span>
            </button>
        </td>
        <td class="scope-label">
            <?php echo Mage::helper( 'turpentine/data' )
                ->__('Save the configuration to a VCL file.')?>
        </td>
    </tr>
    <tr>
        <td class="scope-label">
            <button
                onclick="setLocation('<?php echo $this->getGetConfigUrl()?>')"
                type="button"
                class="scalable">
                <span><?php echo Mage::helper( 'turpentine/data' )
                        ->__('Download Varnish Config') ?></span>
            </button>
        </td>
        <td class="scope-label">
            <?php echo Mage::helper( 'turpentine/data' )
                ->__('Download the generated VCL file.')?>
        </td>
    </tr>
    <tr>
        <?php if( Mage::helper( 'turpentine/varnish' )->isBypassEnabled() ): ?>
            <td class="scope-label">
                <button
                    onclick="setLocation('<?php echo $this->getSwitchNavigationUrl( 'varnish' ); ?>')"
                    type="button"
                    class="scalable back">
                    <span><?php echo Mage::helper( 'turpentine/data' )
                            ->__('Deactivate Varnish Bypass') ?></span>
                </button>
            </td>
            <td class="scope-label">
                <?php echo Mage::helper( 'turpentine/data' )
                    ->__('Remove the bypass cookie and use again Varnish.')?>
            </td>
        <?php else: ?>
            <td class="scope-label">
                <button
                    onclick="setLocation('<?php echo $this->getSwitchNavigationUrl( 'default' ); ?>')"
                    type="button"
                    class="scalable delete">
                    <span><?php echo Mage::helper( 'turpentine/data' )
                            ->__('Activate Varnish Bypass') ?></span>
                </button>
            </td>
            <td class="scope-label">
                <?php echo Mage::helper( 'turpentine/data' )
                    ->__('Create a cookie to bypass Varnish only for your session.')?>
            </td>
        <?php endif; ?>
    </tr>
    <tr>
        <td colspan="2" class="scope-label">
            <form action="<?php echo $this->getFlushPartialUrl(); ?>" method="post" id="partial_url_form">
                <?php echo $this->getBlockHtml('formkey')?>
                <button
                    type="submit"
                    class="scalable delete">
                    <span><?php echo Mage::helper( 'turpentine/data' )
                                ->__('Flush matching URLs') ?></span>
                </button>
                <input id="pattern" name="pattern" type="text" style="width: 295px; margin-left: 5px;" class="required-entry" value="" />
            </form>
            <script type="text/javascript">
                var partialUrlForm = new varienForm('partial_url_form');
                new Varien.searchForm('partial_url_form', 'pattern', '<?php echo Mage::helper( 'turpentine/data' )
                        ->__('Enter a (relative) regex to flush matching URLs')?>');
            </script>
        </td>
    </tr>
</table>
<?php echo $this->getChildHtml(); ?>

<style>
    .varnish-management button {
        width: 190px;
    }
</style>
